package org.aeon.gamechatnest.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.aeon.gamechatnest.pojo.TestEntity;
import org.aeon.gamechatnest.common.response.Result;
import org.aeon.gamechatnest.common.response.ResultBuild;
import org.aeon.gamechatnest.service.TestService;
import org.aeon.gamechatnest.validated.Add;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author: MissingAeon
 * @date: 2024/5/8 13:50
 * @description: 测试 控制器类
 */
@Profile("test")
@Validated
@RestController
@RequestMapping("/test")
@Tag(name = "TestControllerApi", description = "测试控制器类API")
public class TestController {

    @Autowired
    private TestService testService;

    @Operation(
            summary = "从mysql获取一个测试实体",
            description = "获取一个测试实体并返回json",
            parameters = {@Parameter(name = "id", description = "编号")}
    )
    @GetMapping("/mysql/{id}")
    public Result get(@PathVariable("id") Long id) {
        TestEntity testEntity = testService.get(id);
        return ResultBuild.result().successful().data(testEntity).build();
    }

    @Operation(summary = "从mysql添加一个测试实体")
    @PostMapping("/mysql/add")
    public String add(@RequestBody @Validated(Add.class) TestEntity testEntity) {
        boolean result = testService.add(testEntity);
        return "OK:" + result;
    }

    @Operation(summary = "从mysql修改一个测试实体")
    @PutMapping("/mysql/update")
    public String update(@RequestBody @Validated TestEntity testEntity) {
        boolean result = testService.update(testEntity);
        return "OK:" + result;
    }

    @Operation(summary = "从mysql删除一个测试实体")
    @DeleteMapping("/mysql/delete/{id}")
    public String delete(@PathVariable("id") Long id) {
        boolean result = testService.delete(id);
        return "OK:" + result;
    }

    @Operation(
            summary = "从redis获取一个测试实体",
            description = "获取一个测试实体并返回json",
            parameters = {@Parameter(name = "id", description = "编号")}
    )
    @GetMapping("/redis/{id}")
    public Result get2(@PathVariable("id") Long id) {
        TestEntity testEntity = testService.get2(id);
        return ResultBuild.result().successful().data(testEntity).build();
    }

    @Operation(summary = "从redis添加一个测试实体")
    @PostMapping("/redis/add")
    public String add2(@RequestBody @Validated TestEntity testEntity) {
        boolean result = testService.add2(testEntity);
        return "OK:" + result;
    }

    @Operation(summary = "从redis修改一个测试实体")
    @PutMapping("/redis/update")
    public String update2(@RequestBody @Validated TestEntity testEntity) {
        boolean result = testService.update2(testEntity);
        return "OK:" + result;
    }

    @Operation(summary = "从redis删除一个测试实体")
    @DeleteMapping("/redis/delete/{id}")
    public String delete2(@PathVariable("id") Long id) {
        boolean result = testService.delete2(id);
        return "OK:" + result;
    }

    @Operation(
            summary = "从mongodb获取一个测试实体",
            description = "获取一个测试实体并返回json",
            parameters = {@Parameter(name = "id", description = "编号")}
    )
    @GetMapping("/mongodb/{id}")
    public Result get3(@PathVariable("id") Long id) {
        TestEntity testEntity = testService.get3(id);
        return ResultBuild.result().successful().data(testEntity).build();
    }

    @Operation(summary = "从mongodb添加一个测试实体")
    @PostMapping("/mongodb/add")
    public String add3(@RequestBody @Validated TestEntity testEntity) {
        boolean result = testService.add3(testEntity);
        return "OK:" + result;
    }

    @Operation(summary = "从mongodb修改一个测试实体")
    @PutMapping("/mongodb/update")
    public String update3(@RequestBody @Validated TestEntity testEntity) {
        boolean result = testService.update3(testEntity);
        return "OK:" + result;
    }

    @Operation(summary = "从mongodb删除一个测试实体")
    @DeleteMapping("/mongodb/delete/{id}")
    public String delete3(@PathVariable("id") Long id) {
        boolean result = testService.delete3(id);
        return "OK:" + result;
    }
}
